package mylibrary.xml.dom;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


public class Test {

	public static void main(String[] args) throws Exception {
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setValidating(false);
		//factory.setNamespaceAware(false);
		
		DocumentBuilder builder = factory.newDocumentBuilder();
		
		Document doc = builder.parse(new File("bin\\mylibrary\\xml\\dom\\test.xml"));
		
		Element elementCollection = doc.getDocumentElement();
		
		NodeList beanList = elementCollection.getElementsByTagName("bean");
		for(int i=0; i<beanList.getLength(); i++) {
			Element e = (Element) beanList.item(i);
			System.out.println(e.getAttribute("id"));
			System.out.println(e.getAttribute("class"));
			
		}
		
		System.out.println("----------------------");		
		
		NodeList adviceList = elementCollection.getElementsByTagName("ns2:advice");
		for(int i=0; i<adviceList.getLength(); i++) {
			Element e = (Element) adviceList.item(i);
			System.out.println(e.getAttribute("id"));
			System.out.println(e.getAttribute("transaction-manager"));
			
		}
		
		System.out.println("----------------------");		
		
		NodeList methodList = elementCollection.getElementsByTagName("tx:method");
		for(int i=0; i<methodList.getLength(); i++) {
			Element e = (Element) methodList.item(i);
			System.out.println(e.getAttribute("name"));
			System.out.println(e.getAttribute("propagation"));
			
		}

	}
}
